package com.huixi.microspur.web.controller.appeal;


import cn.hutool.core.bean.BeanUtil;
import com.huixi.microspur.commons.base.BaseController;
import com.huixi.microspur.commons.util.wrapper.WrapMapper;
import com.huixi.microspur.commons.util.wrapper.Wrapper;
import com.huixi.microspur.web.entity.appeal.*;
import com.huixi.microspur.web.service.WjAppealMaterialService;
import com.huixi.microspur.web.service.WjAppealService;
import com.huixi.microspur.web.service.WjAppealTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 诉求表 前端控制器
 * </p>
 *
 * @author xzl
 * @since 2020-01-17
 */
@RestController
@RequestMapping("/wjAppeal")
@Api(tags = "诉求模块的接口")
public class WjAppealController extends BaseController {

    @Autowired
    private WjAppealService wjAppealService;

    @Autowired
    private WjAppealMaterialService wjAppealMaterialService;

    @Autowired
    private WjAppealTagService wjAppealTagService;

    /**
     *  按条件分页查询 诉求
     * @Author 叶秋
     * @Date 2020/2/26 21:14
     * @param listPageAppealVO
     **/
    @PostMapping("/listPageAppeal")
    @ApiOperation(value = "按条件分页查询 诉求")
    public Wrapper listPageAppeal(@RequestBody ListPageAppealVO listPageAppealVO){

        // 多表拼凑 数据
        ArrayList<QueryAppealVO> queryAppealVOS = new ArrayList<>();
        QueryAppealVO queryAppealVO ;

        List<WjAppeal> wjAppeals = wjAppealService.listPageAppeal(listPageAppealVO);

        for (WjAppeal wjAppeal : wjAppeals) {
            queryAppealVO = new QueryAppealVO();

            // 查询相关素材
            List<WjAppealMaterial> wjAppealMaterials = wjAppealMaterialService.listByAppealId(wjAppeal.getAppealId());
            queryAppealVO.setAppealMaterial(wjAppealMaterials);
            // 查询相关标签
            List<WjAppealTag> wjAppealTags = wjAppealTagService.listByAppealTag(wjAppeal.getAppealId());
            queryAppealVO.setAppealTag(wjAppealTags);


            BeanUtil.copyProperties(wjAppeal, queryAppealVO, true);
            queryAppealVOS.add(queryAppealVO);
        }


        return WrapMapper.ok(queryAppealVOS);
    }


}

